package com.yanqu.road.server.manger.relatives.task;

import com.yanqu.road.entity.relatives.RelativesInfo;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.relatives.RelativesModule;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.manger.relatives.RelativesMgr;
import com.yanqu.road.utils.executor.GeneralTask;

public class AddCrossMarryTimesTask extends GeneralTask {

    long userId;

    long relativesId;

    long relativesServerId;

    public AddCrossMarryTimesTask(long userId, long relativesId, long relativesServerId) {
        this.userId = userId;
        this.relativesId = relativesId;
        this.relativesServerId = relativesServerId;
    }

    public long getUserId() {
        return userId;
    }

    public void setUserId(long userId) {
        this.userId = userId;
    }

    public long getRelativesId() {
        return relativesId;
    }

    public void setRelativesId(long relativesId) {
        this.relativesId = relativesId;
    }

    public long getRelativesServerId() {
        return relativesServerId;
    }

    public void setRelativesServerId(long relativesServerId) {
        this.relativesServerId = relativesServerId;
    }

    @Override
    public void doRun() {
        boolean load = RelativesMgr.isLoadUserRelatives(userId);
        if(!load){
            RelativesMgr.loadRelativesInfo(userId);
        }
        RelativesInfo relativesInfo = RelativesMgr.addMarriageTimes(userId, relativesId);

        GamePlayer player = GamePlayerMgr.getOnlinePlayer(userId);
        if(player != null){
            player.getModule(RelativesModule.class).getRelativesMap().put(relativesId, relativesInfo);
        }

        RelativesMgr.getLogger().info("cross marry times {}, {}", userId, relativesId);
    }
}
